#include // Comes with Arduino IDE #include LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address /* Pin to interrupt map: * D0-D7 = PCINT 16-23 = PCIE2 = pcmsk2 * D8-D13 = PCINT 0-5 = PCIE0 = pcmsk0 * A0-A5 (D14-D19) = PCINT 8-13 = PCIE1 = pcmsk1 */ #define interrupt_pin2 8 //Define Analog Pin (analog pins are 16-21) volatile unsigned long t=0; volatile unsigned long ot=0; ISR(PCINT0_vect) { if (PINB & 1) { ot=t; t=millis(); } } //actualizar o visor (aqui calibrado para um maximo de 3000 rpm, basta mudar o valor) #define max_rpm 3000 void printVu(int r) { int i=map(r, 0, max_rpm, 0, 20); for(int n=0;n<20;n++) { lcd.print((char)(n300) rpm=0; else if (t!=ot) { rpm=60000.0/(float)(t-ot); } Serial.print(rpm);Serial.print(" ");Serial.println(t-ot); lcd.setCursor(0,1); lcd.print(rpm); lcd.print(" rpms "); lcd.setCursor(0,2); printVu(rpm); }